package com.group2.equipment.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.group2.equipment.entity.DataDictionaryVO;
import com.group2.equipment.service.DataDictionaryService;
import com.group2.equipment.service.blockhandler.BlockHandlerService;
import com.group2.equipment.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author binghan
 * @version 1.0
 * @description: TODO 数据字典控制层
 * @date 2022/6/6 16:50
 */
@RestController
@RequestMapping("/dataDictionary")
public class DataDictionaryController {

    @Autowired
    private DataDictionaryService dataDictionaryService;

    @GetMapping("/queryAll")
    @SentinelResource(value = "queryDataDictionary",blockHandler = "queryBlockHandler", blockHandlerClass = BlockHandlerService.class)
    public Result queryDataDictionary() {
        // 返回结果信息
        Result<List<DataDictionaryVO>> res = new Result<>();
        try {
            // 获取返回数据
            List<DataDictionaryVO> dataDictionaryVOList = dataDictionaryService.queryDataDictionary();
            // 返回数据信息
            res.setData(dataDictionaryVOList);
            //  返回数据成功
            res.setSuccess();
        } catch (Exception e) {
            e.printStackTrace();
            // 返回数据失败
            res.setError();
            res.setData(null);
        }
        return res;
    }
}
